<template>
  <el-container>
    <el-aside width="200px">

      <SideMenu></SideMenu>

    </el-aside>
    <el-container>
      <!--      el-header为右边上部分-->
      <el-header>
        <strong>Vue后台管理系统</strong>
        <div class="header-avatar">
          <!--下一行是头像图像-->
          <el-avatar size="medium" src="userInfo.avatar"></el-avatar>

          <!--          Admin的下拉菜单-->
          <el-dropdown>
             <span class="el-dropdown-link">
             {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
             </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <router-link :to="{name :'UserCenter'}">个人中心</router-link>
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

          <el-link href ="https://mail.qq.com/" target="_blank">QQ邮箱</el-link>
          <el-link href ="https://gitee.com/li-l03" target="_blank">git</el-link>
        </div>
      </el-header>
      <!--      右边下部分-->
      <el-main>
        <router-view></router-view>
      </el-main>

    </el-container>
  </el-container>
</template>


<!--下面script调用SideMenu.vue里的-->
<script>
import SideMenu from "./inc/SideMenu";
export default {
  name: "Home",
  components:{
    SideMenu
  },

  data(){
    return{
      userInfo: {
        id: "",
        username: "",
        //下面头像
        avatar: ""
      }
    }
  },

  created() {
    this.getUserInfo()
  },
  methods:{
    getUserInfo(){
      this.$axios.get("/sys/userInfo").then(res=>{
        this.userInfo=res.data.data
      })
    },
    logout(){
      this.$axios.post("/logout").then(res=>{
        localStorage.clear()
        sessionStorage.clear()

        this.$store.commit("resetState")

        this.$router.push("/login")

      })
    }
  }
}
</script>


<style scoped>
.el-container {
  padding: 0;
  margin: 0;
  height: 100%;
}


.header-avatar{
  float: right;
  width: 210px;
  /*下面一三行：使得交叉居中，第三行是上下居中*/
  display: flex;
  /*下面一行:使其不紧密，位置更加扩展舒缓*/
  justify-content: space-around;
  align-items: center;
}


.el-dropdown-link {
  /*鼠标变小手*/
  cursor: pointer;
}
.el-icon-arrow-down {
  /*下拉框小箭头*/
  font-size: 12px;
}


/*顶部*/
.el-header {
  background-color: #17B3A3;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  line-height: 200px;
}

.el-main {
  color: #333;
  text-align: center;
  /*line-height: 160px;*/
}
a{
  text-decoration: none;
}

</style>
